var updateform;

function showHistory(e,id) {
	his = new Poat({center: true});
	his.event = e;
	his.execute("loadHistory",id);
	return false;
}

function showWorkload(e,teamid) {
	work = new Poat();
	work.event = e;
	work.execute("workload",teamid);
	return false;
}

function showMyFiles(e) {
	work = new Poat({width: 300});
	work.event = e;
	work.execute("listMyFiles");
	return false;
}

function removeFile(id,prj) {
	showprogress();
	xajax_removeFile(id,prj);		
}

function addFile() {
	showprogress();
	xajax_addFile(xajax.getFormValues("add_file_form"));		
}

function showUpdateForm(e, form, rowId, fileName, newStatus, stamp,cuser,content) {
	updatewindow = new Poat({width: 450});
	updatewindow.event = e;
	updatewindow.result = content;
	updatewindow.name = "update_file_status_window";
	updatewindow.response(fileName);

	var forma = document.getElementById(form);
	
	switch(newStatus) {
		case 'locked':
		  status = 'chkpnd';
		  break;    
		case 'cmpnd':
		  status = 'chkpnd';
		  break;
		case 'chkpnd':
		  status = 'proof';
		  break;		
		case 'proof':
		  status = 'done';
		  break;
		default:
		  status = 'locked';
	}

	forma.id.value=rowId;
	forma.fstamp.value=stamp;
	forma.newstatus.value=status;
	forma.assignto.value=cuser;
	forma.comment.focus();
}

function goUpload() {
	var forma = document.getElementById("reload");
	forma.action.value="fileupload";		
	forma.submit();
}
function setOrder(order) {
	var forma = document.getElementById("reload");
	forma.op.value="order";
	forma.forder.value=order;
	loadFileList();
}
function gotopage(page) {
	var forma = document.getElementById("reload");
	forma.currentpage.value=page;
	loadFileList();
}

function addfilter(field,el) {
	//var forma = document.getElementById("reload");
	var forma = document.forms["reload"];
	forma.currentpage.value=1;
	if (el.checked!=undefined) {
		if (el.checked) {
			forma[field].value=el.value;		
		} else {
			forma[field].value="";
		}
	} else if (el.selectedIndex!=undefined) {
		forma[field].value = el.options[el.selectedIndex].value;
	} else {
		forma[field].value=el.value;
	}
	loadFileList();
}
	
function updateRequestList() {
	showprogress();
	xajax_updateFile(xajax.getFormValues("update_file_status_form"));
	WindowControl.destroy("update_file_status_window");
}

function loadFileList() {
	showprogress();
	// Konqueror is bullshit
	if (BrowserDetect.browser == "Konqueror") {
		browseTo(xajax.getFormValues("reload"));
	} else {
		xajax_getFileList(xajax.getFormValues("reload"));
	}
}

	
function sendFileList(e) {
	showprogress();
	xajax_sendMeMyFiles();
	return false;
}

function initUpdateForm(content) {
	updateform = content;
}